#include <iostream>
using namespace std;

string s = "0123456789ABCDEF";

void func(int x, int m)
{
	if(x >= m)
		func(x / m, m);
	cout << s[x % m];
}

int main()
{
	int x, m;
	cin >> x >> m;
	func(x, m);
	return 0;
}
